<?php

namespace App\Models;

use Illuminate\Database\Eloquent\Model;
//use Illuminate\Foundation\AuthController\User as AuthUser;
//引入软删除
use Illuminate\Database\Eloquent\SoftDeletes;
//引入按钮权限检测
use App\Models\Traits\But;

/**
 * App\Models\Base
 *
 * @method static bool|null forceDelete()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Base newModelQuery()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Base newQuery()
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Base onlyTrashed()
 * @method static \Illuminate\Database\Eloquent\Builder|\App\Models\Base query()
 * @method static bool|null restore()
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Base withTrashed()
 * @method static \Illuminate\Database\Query\Builder|\App\Models\Base withoutTrashed()
 * @mixin \Eloquent
 */
class Base extends Model
{
    //使用SoftDeletes trait
    use SoftDeletes,But;
    //添加软删除字段
    protected $dates = ['delete_at'];
    protected $guarded = [];

    public function get_tree_list($list)
    {
        //将每条数据中的id值作为其下标
        $temp = [];
        foreach ($list as $v) {
            $v['son'] = [];
            $temp[$v['id']] = $v;
        }
        //获取分类树
        foreach ($temp as $k => $v) {
            $temp[$v['pid']]['son'][] = &$temp[$v['id']];
        }
        return isset($temp[0]['son']) ? $temp[0]['son'] : [];
    }

}
